﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Net.Http;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using Mobileterminal.Common;
using Mobileterminal.Dtos;
using Mobileterminal.Dtos.Yjb;
using Newtonsoft.Json;
using Sunny.UI;

namespace Mobileterminal.Forms
{
    public partial class AddConsumableMaterial : UIEditForm
    {
        //public static List<ConsumTypeTree> appsTypes = new List<ConsumTypeTree>();
        public AddConsumableMaterial()
        {
            InitializeComponent();
            //GetApps();
        }


        //获取分类对应的分类名称--下拉框
        //private async Task GetApps()
        //{
        //    var url = "https://localhost:7224/api/ApparatusType/QueryApparatusType";


        //    var json = await HttpClientHelper.ClientAsync("GET", url);
        //    var result = Newtonsoft.Json.JsonConvert.DeserializeObject<Result<List<ConsumTypeTree>>>(json);
        //    if (result.Code == 200)
        //    {
        //        uiComboBox1.DataSource = result.Data;
        //        uiComboBox1.DisplayMember = "ConsumTypeTypeName";
        //        uiComboBox1.ValueMember = "ConsumTypeId";
        //        appsTypes = result.Data;
        //    }
        //}
        private void label1_Click(object sender, EventArgs e)
        {

        }

        private void label1_Click_1(object sender, EventArgs e)
        {

        }

        private void label2_Click(object sender, EventArgs e)
        {

        }

        private void label4_Click(object sender, EventArgs e)
        {

        }

        private void label6_Click(object sender, EventArgs e)
        {

        }

        private void label5_Click(object sender, EventArgs e)
        {

        }

        private void uiTextBox4_TextChanged(object sender, EventArgs e)
        {

        }

        //确定按钮
        private async void btnOK_Click(object sender, EventArgs e)
        {
            var pdata = new
            {
                ConsumableId = 0,
                ConsumableCode = uiTextBox5.Text,
                Manufacturer = uiTextBox6.Text,
                UnitPrice = uiTextBox1.Text,
                Unit = uiTextBox2.Text,
                Specification = uiTextBox3.Text,
                ConsumableName = uiTextBox4.Text,
                Consumabletype = uiTextBox7.Text,
            };
            string jsonParam = JsonConvert.SerializeObject(pdata);
            HttpContent httpContent = new StringContent(jsonParam, Encoding.UTF8, "application/json");
            var json = await HttpClientHelper.ClientAsync("post", "https://localhost:7286/api/Yjb/AddConsum", true, httpContent);
            shelefs result = JsonConvert.DeserializeObject<shelefs>(json);


            if (result != null)
            {
                MessageBox.Show("添加成功");
                this.DialogResult = DialogResult.OK;  // 先设置结果
                this.Close();

            }
        }


        private void uiTextBox7_TextChanged(object sender, EventArgs e)
        {

        }

        private void pnlBtm_Click(object sender, EventArgs e)
        {

        }

        private void button1_Click(object sender, EventArgs e)
        {

        }
    }
}
